
import 'package:aqua_plunge/widget/PlayerWidget.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';

class AudioPlayBar extends StatefulWidget {
  final String audioPath;
  const AudioPlayBar({super.key, required this.audioPath});

  @override
  State<AudioPlayBar> createState() => _AudioPlayBarState();
}

class _AudioPlayBarState extends State<AudioPlayBar> {

  late AudioPlayer player;

  @override
  void initState() {
    super.initState();
    player = AudioPlayer();
    player.setReleaseMode(ReleaseMode.stop);
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await player.setSourceDeviceFile(widget.audioPath);
      await player.stop();
    });
  }

  @override
  void dispose() {
    player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      height: 40,
      width: 195,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
          color: Colors.white
      ),
      child: PlayerWidget(player: player),
    );
  }
}

